package com.empire.module.rainbow.controller.app.diy;

import com.empire.module.rainbow.controller.app.diy.vo.AppRainbowDiyPagePageReqVO;
import com.empire.module.rainbow.controller.app.diy.vo.AppRainbowDiyPageRespVO;
import com.empire.module.rainbow.controller.app.diy.vo.AppRainbowDiyPageSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.security.PermitAll;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.CommonResult;
import com.empire.framework.common.util.object.BeanUtils;
import static com.empire.framework.common.pojo.CommonResult.success;

import com.empire.framework.excel.core.util.ExcelUtils;

import com.empire.framework.apilog.core.annotation.ApiAccessLog;
import static com.empire.framework.apilog.core.enums.OperateTypeEnum.*;

import com.empire.module.rainbow.dal.dataobject.diypage.RainbowDiyPageDO;
import com.empire.module.rainbow.service.diypage.RainbowDiyPageService;

@Tag(name = "用户 APP - 六彩-装修页面")
@RestController
@RequestMapping("/rainbow/diy-page")
@Validated
public class AppRainbowDiyPageController {

    @Resource
    private RainbowDiyPageService rainbowDiyPageService;

    @PostMapping("/create")
    @Operation(summary = "创建六彩-装修页面")
    public CommonResult<Long> createDiyPage(@Valid @RequestBody AppRainbowDiyPageSaveReqVO createReqVO) {
        return success(rainbowDiyPageService.createDiyPage(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新六彩-装修页面")
    public CommonResult<Boolean> updateDiyPage(@Valid @RequestBody AppRainbowDiyPageSaveReqVO updateReqVO) {
        rainbowDiyPageService.updateDiyPage(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除六彩-装修页面")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteDiyPage(@RequestParam("id") Long id) {
        rainbowDiyPageService.deleteDiyPage(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得六彩-装修页面")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PermitAll
    public CommonResult<AppRainbowDiyPageRespVO> getDiyPage(@RequestParam("id") Long id) {
        RainbowDiyPageDO diyPage = rainbowDiyPageService.getDiyPage(id);
        return success(BeanUtils.toBean(diyPage, AppRainbowDiyPageRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得六彩-装修页面分页")
    public CommonResult<PageResult<AppRainbowDiyPageRespVO>> getDiyPagePage(@Valid AppRainbowDiyPagePageReqVO pageReqVO) {
        PageResult<RainbowDiyPageDO> pageResult = rainbowDiyPageService.getDiyPagePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppRainbowDiyPageRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出六彩-装修页面 Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDiyPageExcel(@Valid AppRainbowDiyPagePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<RainbowDiyPageDO> list = rainbowDiyPageService.getDiyPagePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "六彩-装修页面.xls", "数据", AppRainbowDiyPageRespVO.class,
                        BeanUtils.toBean(list, AppRainbowDiyPageRespVO.class));
    }

}
